<?php

/**
 * Show people who you liked
 * @author Tuan Hoang <hoangtuan438@gmail.com> 
 */
class Interested extends CWidget {

    public function run() {
	/**
	 * get random interested
	 */
	$model = array();
	$user = user()->getModel()->ideal_profile;
	if (isset(user()->getModel()->postcode) && user()->getModel()->postcode) {
	    $sql = 't.postcode=' . user()->getModel()->postcode . ' AND t.user_id!=' . user()->id . ' AND t.gender != "' . user()->getModel()->gender . '"';
	} else {
	    $sql = 't.user_id!=' . user()->id . ' AND t.gender != "' . user()->getModel()->gender . '"';
	}
	if ($user) {
	    if ($user['age_from'] && $user['age_to']) {
		$sql .= ' AND t.age BETWEEN ' . $user['age_from'] . ' AND ' . $user['age_to'];
	    }
	}
	$sql .= ' AND t.type!="admin"';
	$model = User::model()->findAll(array(
	    'condition' => $sql,
	    'order' => 'rand()'
	));


	$this->render('interested', array('model' => $model));
    }

}
